import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;

public class Demo3 {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            connection = JDBC.getConnection();
            String sql = "select student_id, sn, name, mail, class_id from student";
            preparedStatement = connection.prepareStatement(sql);

            resultSet = preparedStatement.executeQuery();

            while (resultSet.next()) {
                Long student_id = (Long)resultSet.getLong("student_id");
                String sn = resultSet.getString("sn");
                String name = resultSet.getString("name");
                String mail = resultSet.getString("mail");
                Long class_id = (Long)resultSet.getLong("class_id");
                System.out.println(MessageFormat.format("student_id = {0}, sn = {1}, name = {2}, mail = {3}, class_id = {4}",
                        student_id, sn, name, mail, class_id));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
//            JDBC.close(null, null, null);
            JDBC.close(resultSet, preparedStatement, connection);
        }

    }
}
